<template>
	<view class="ys">

		<view class="infobox">
			<view class="title">
				收货信息
			</view>
			<view class="infoli">
				<text class="left">收货人姓名</text>
				<text class="left">{{orderinfo.name}}</text>
			</view>
			<view class="infoli">
				<text class="left">收货人手机号</text>
				<text class="left">{{orderinfo.phone}}</text>
			</view>
			<view class="infoli">
				<text class="left">详细地址</text>
				<text class="right">{{orderinfo.address}}</text>
			</view>
		</view>
		<view class="infobox" v-if="goods_info != ''">
			<view class="title">
				商品信息
			</view>
			<view class="goodsitem">
				<view class="item">
					<image :src="goods_info.logo_url | getImg" mode=""></image>
					<view class="g-infobox">
						<view class="g-title">
							{{goods_info.name}}
						</view>
						<view class="g-price">
							<view class="pricebox">
								<text class="price">￥{{goods_info.price}}</text>
							</view>
							<text>×{{orderinfo.num}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="infobox" v-if="orderinfo !=''">
			<view class="title">
				订单信息
				<text>{{order_status[orderinfo.status]}}</text>
			</view>
			<view class="infoli">
				<text>订单编号</text>
				<view class="ordernum" @click="copy">
					{{orderinfo.order_id}}
					<uni-icons type="compose" size="18"></uni-icons>
				</view>
			</view>
			<view class="infoli time">
				<text class="left">下单时间</text>
				<text class="left">{{orderinfo.add_time | ysTime}}</text>
			</view>
			<view class="infoli time">
				<text class="left">优惠券</text>
				<text class="left">{{orderinfo.quan__name || '无'}}</text>
			</view>
			<view class="infoli time">
				<text class="left">抵扣</text>
				<text class="left">{{orderinfo.quan_use || '0.00'}}</text>
			</view>

			<!-- 	<view class="infoli time">
				<text class="left">PV</text>
				<text class="left">{{orderinfo.total_pv}}</text>
			</view>
			<view class="infoli time">
				<text class="left">邮费</text>
				<text class="left">{{orderinfo.postage}}</text>
			</view>
			<view class="infoli time">
				<text class="left">备注</text>
				<text class="left">{{orderinfo.remarks || '未填写'}}</text>
			</view> -->
		</view>
		<view class="infobox" v-if="orderinfo.express_name">
			<view class="title">
				查看物流
			</view>
			<view class="infoli">
				<text class="left">快递名称</text>
				<text class="left">{{orderinfo.express_name || ''}}</text>
			</view>
			<view class="infoli">
				<text class="left">快递单号</text>
				<text class="left">{{orderinfo.express_num || ''}}</text>
			</view>
		</view>
		<view class="infobox" v-if="orderinfo.is_evaluate == 1">
			<view class="title">
				订单评价
			</view>
			<view class="plbox">
				<textarea v-model="content" placeholder="请输入内容"></textarea>
				<image :src="plimg || '/static/sendimg.png'" @click="uploadImg" mode=""></image>
			</view>
		</view>
		<view class="footer">
			<text></text>
			<view class="right">
				<view class="total">
					实付款：<text>￥{{orderinfo.pay_amount || 0}}</text>
				</view>
				<button @tap="submitInfo" v-if="orderinfo.status == 0">立即支付</button>
				<button @tap="Evaluate" v-if="orderinfo.status == 3 && orderinfo.is_evaluate == 1">立即评论</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		setTimeout
	} from "timers"
	import {
		OrderDetail,
		Evaluate
	} from "@/api/shop.js"
	export default {
		data() {
			return {
				order_id: '',
				orderinfo: [],
				order_status: [],
				order_status_msg: [],
				service_time: [],
				order_comment: '',
				sf_comment: '',
				choose_sfid: 0,
				sflist: [1, 2, 3],
				amount: 0,
				contact_name: '',
				contact: '',
				goods_info: [],
				pick_address: '',
				plimg: '',
				content: ''
			}
		},
		onLoad(e) {
			this.order_id = e.id
			this.OrderDetail()
		},
		methods: {
			Evaluate() {
				Evaluate({
					order_id: this.order_id,
					img: this.plimg,
					content: this.content
				}).then(res => {
					uni.$showMsg(res.message)
					if (res.status == 1) {
						setTimeout(() => {
							uni.navigateBack()
						}, 500)
					}
				})
			},
			call(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				})
			},
			toAddress() {
				uni.openLocation({
					latitude: Number(this.wei),
					longitude: Number(this.jing),
					address: this.ti_address,
					name: this.ti_address,
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					}
				})
			},
			toPage(url) {
				uni.navigateTo({
					url
				})
			},
			uploadImg() {
				let that = this
				uni.chooseImage({
					sourceType: ['album', 'camera'], //从相册选择
					count: 1,
					success: (res) => {
						let igmFile = res.tempFilePaths;
						uni.showLoading({
							mask: true,
							title: '加载中'
						})
						for (let i = 0; i < igmFile.length; i++) {
							uni.uploadFile({
								url: that.$config.requestUrl +
									'/Index/forUpload',
								header: {
									'token': uni.getStorageSync('token')
								},
								formData: {
									accept: 'image',
								},
								filePath: igmFile[i],
								name: 'image',
								success: (res) => {
									uni.hideLoading()
									let imgRes = JSON.parse(res.data); //微信和头条支持
									if (imgRes.status == 1) {
										let imgData = imgRes.data
										that.plimg = that.$config.websiteUrl + imgData
									} else {
										uni.showToast({
											title: res.message,
											icon: "none"
										})
										return
									}
								},
								fail(err) {
									uni.hideLoading()
								}
							})
						}
					},
				});
			},
			SFinfo() {
				uni.navigateTo({
					url: '/pages/master/info?do_uid=' + this.orderinfo.do_uid
				})
			},
			submitInfo() {
				uni.navigateTo({
					url: `/pages/orderpay/index?order_id=${this.orderinfo.order_id}&amount=${this.orderinfo.pay_amount}`
				})
			},
			CancelOrder() {
				var that = this
				uni.showModal({
					title: '温馨提示',
					content: '是否取消订单？',
					success(res) {
						if (res.confirm) {
							CancelOrder({
								order_id: that.order_id
							}).then(data => {
								uni.showToast({
									title: data.msg,
									icon: "none"
								})
								if (data.code == 200) {
									setTimeout(() => {
										uni.navigateBack()
									}, 500)
								}
							})
						}
					}
				})
			},
			copy() {
				uni.setClipboardData({
					data: this.orderinfo.order_id
				})
			},

			OrderDetail() {
				OrderDetail({
					order_id: this.order_id
				}).then(res => {
					this.orderinfo = res.data.order
					this.goods_info = this.orderinfo.GoodsInfo
					this.order_status = res.data.status
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		min-height: calc(100vh - 44px);
		background: linear-gradient(180deg, #FF3C29, #f9f9f9, #f9f9f9);
		padding: 10px 0;
		padding-bottom: 70px;
		box-sizing: border-box;
		background-repeat-y: no-repeat;
		font-size: 14px;
	}

	.goodsitem {
		display: flex;
		flex-direction: column;

		.item {
			display: flex;
			align-items: center;
			padding: 10px;
			box-sizing: border-box;
			border-bottom: 1px solid #eee;

			image {
				width: 70px;
				height: 70px;
				margin-right: 30rpx;
			}

			.g-infobox {
				flex: 1;
				display: flex;
				justify-content: space-between;
				flex-direction: column;
				height: 65px;

				.g-price {
					display: flex;
					justify-content: space-between;
					font-size: 14px;
					color: #999;

					.pricebox {
						display: flex;
						align-items: flex-end;

						.price {
							color: #FF3C29;
							font-weight: bold;
						}

						.oldprice {
							font-size: 12px;
							margin-left: 8px;
							color: #999;
							text-decoration: line-through;
						}
					}

				}
			}
		}

		.item:last-child {
			border: 0;
		}
	}

	.footer {
		height: 55px;
		padding: 10px;
		position: fixed;
		left: 50%;
		transform: translate(-50%);
		bottom: 0;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #fff;
		box-sizing: border-box;
		max-width: 500px;

		.total {
			color: #999;

			text {
				color: #f00;
				font-weight: bold;
			}
		}

		.canle {
			color: #999;
		}

		.right {
			display: flex;
			align-items: center;
			justify-content: space-between;

			button {
				background: linear-gradient(70deg, #FF3C29, #FF3C29d1, #FF3C29);
				color: #fff;
				width: 80px;
				padding-left: 0;
				padding-right: 0;
				font-size: 14px;
				margin: 0;
				margin-left: 10px;
			}
		}

	}

	.top {
		padding: 10px;
		font-size: 30upx;
		color: #000;
		background: #fff;
		border-radius: 5px;
		width: 96%;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-sizing: border-box;

		.tips {
			display: flex;
			flex-direction: column;

			.tips-msg {
				font-size: 14px;
				color: #999;
				margin-top: 5px;
			}
		}

		.kefu {
			display: flex;
			align-items: center;
			font-size: 12px;
			white-space: nowrap;

			button {
				background: transparent;
				font-size: 12px;
				border: unset;
				outline: 0;
				box-sizing: 0;
				padding: 0;
				padding-left: 5px;
			}

			text {
				margin-left: 3px;
			}
		}

	}

	.infobox {
		background-color: #fff;
		width: 96%;
		margin: 0 auto;
		border-radius: 5px;
		margin-top: 10px;
		padding: 10px 0;
		box-shadow: 0 0 5px #f3f3f3;

		.plbox {
			padding: 0 10px;
			margin-top: 10px;

			image {
				width: 80px;
				height: 80px;
				margin-top: 10px;
			}
		}

		textarea {
			width: 100%;
			font-size: 14px;
			padding: 10px;
			box-sizing: border-box;
			border: 1px solid #eee;
			border-radius: 5px;
		}

		.title {
			padding: 10px;
			padding-top: 0;
			font-weight: bold;
			font-size: 14px;
			display: flex;
			justify-content: space-between;
			align-items: center;

			text {
				font-weight: normal;
				background: #FF3C29;
				color: #fff;
				border-radius: 3px;
				padding: 2px 5px;
				font-size: 12px;
			}
		}

		.imgbox {
			padding: 0 10px;

			image {
				width: 50px;
				height: 50px;
				border-radius: 3px;
			}
		}

		.infoli {
			display: flex;
			padding: 10px;
			box-sizing: border-box;
			justify-content: space-between;

			input {
				text-align: right;
				padding: 0 5px;
				border-bottom: 1px solid #eee;
				font-size: 14px;
			}

			.right {
				width: 60%;
				text-align: right;
			}

			.ordernum {
				display: flex;
				align-items: center;

				text {
					margin-left: 5px;
				}
			}

			.tiaddress {
				display: flex;
				align-items: center;
				justify-content: flex-end;
			}

			.sfitem {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				border: 1px solid #fff;
				padding: 5px;
				border-radius: 5px;

				.left {
					display: flex;
					align-items: center;
				}

				.right {
					color: #f00;
				}

				image {
					width: 40px;
					height: 40px;
					margin-right: 10px;
					border-radius: 5px;
				}
			}

			.active {
				border-color: #FF3C29;
			}

			textarea {
				width: 100%;
				border: 1px solid #eee;
				border-radius: 5px;
				padding: 5px;
				box-sizing: border-box;
				font-size: 14px;
			}
		}

		.time {
			text {
				white-space: nowrap;
			}
		}
	}

	.textareabox {
		flex-direction: column;
	}

	.showbox {
		textarea {
			min-height: 100px;
		}
	}
</style>